<template>
  <j-modal :title="title" :fullscreen="true" :visible="visible" :maskClosable="false" @close="close" destroyOnClose>
    <h3>{{title2}}</h3>
    <a-table
      v-if="type != '3'"
      ref="table"
      size="middle"
      bordered
      rowKey="id"
      :columns="columns"
      :dataSource="dataSource"
      :pagination="ipagination"
      :loading="loading"
      @change="handleTableChange"
      class="antableClass"
    ></a-table>
    <div v-else>
      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :customRow="handleClickRow"
        @change="handleTableChange"
        class="antableClass"
      ></a-table>
      <table v-if="assistData.length > 0" border="1" align="center" valign="center" class="assist-table">
        <tr style="text-align: center">
          <th v-for="(item, index) in assistData" :key="index" class="assist-table-title">{{ item.sortName }}</th>
        </tr>
        <tr style="text-align: center">
          <td v-for="(item, index) in assistData" :key="index + 1" class="assist-table-item">{{ item.itemName }}</td>
        </tr>
      </table>

      <div v-else>
        <a-divider />
        <a-empty style="margin-top: 20px">
          <div slot="description">
            <span v-if="!assistLoading">暂无数据，请点击上方表格其他行，查看数据</span>
            <a-spin v-else />
          </div>
        </a-empty>
      </div>
    </div>
  </j-modal>
</template>

<script>
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import { deleteAction, getAction, postAction } from '@/api/manage'
import { columns4, columns5, columns6 } from './columns'
export default {
  name: 'ProjectQualityDetails',
  mixins: [JeecgListMixin],
  data() {
    return {
      queryParam: {
        id: '',
        type: ''
      },
      columns: [],
      assistData: [],
      visible: false,
      title: '详情列表',
      titles: ['设备物资点收', '供应商进场','凭证和辅助'],
      title2:'',
      lists: ['/sjmx/queryMatChkinOdrData', '/sjmx/queryDvceInRegOdrData', '/sjmx/queryVoucherDetailData'],
      url: {
        list: '/sjmx/queryGcxmzlcbtzxXq',
        assistList: '/sjyzzx/sjZxzyAssistAccount/queryAssistByEntryId'
      },
      type: '1',
      assistLoading: false
    }
  },
  methods: {
    close() {
      this.visible = false
    },
    edit(record, params) {
      let { id, type } = record
      let { orgId } = params
      this.queryParam.id = id
      this.queryParam.orgId = orgId
      this.type = type
      switch (type) {
        case '1':
          this.columns = columns5()
          this.url.list = this.lists[0]
          this.title2 = this.titles[0]
          break
        case '2':
          this.columns = columns4()
          this.url.list = this.lists[1]
          this.title2 = this.titles[0]
          break
        case '3':
          this.columns = columns6()
          this.url.list = this.lists[2]
          this.title2 = this.titles[0]
          break
        default:
          break
      }
      this.loadData(1)
      this.visible = true
    },
    handleClickRow(record, index) {
      return {
        on: {
          click: () => {
            this.getAssistDetailData(record.id)
          }
        }
      }
    },
    loadData(arg) {
      if (!this.url.list) {
        this.$message.error('请设置url.list属性!')
        return
      }
      // 加载数据 若传入参数1则加载第一页的内容
      if (arg === 1) {
        this.ipagination.current = 1
      }
      var params = this.getQueryParams() // 查询条件
      this.loading = true
      // this.dataSource=[]
      getAction(this.url.list, params).then(res => {
        if (res.success) {
          // update-begin---author:zhangyafei    Date:20201118  for：适配不分页的数据列表------------
          this.dataSource = res.result.records || res.result
          if (this.dataSource.length > 0 && this.type == '3') this.getAssistDetailData(this.dataSource[0].id)
          if (res.result.total) {
            this.ipagination.total = res.result.total
          } else {
            this.ipagination.total = 0
          }
          // update-end---author:zhangyafei    Date:20201118  for：适配不分页的数据列表------------
        } else {
          this.$message.error(res.message)
        }
        if (res.code === 510) {
          this.$message.warning(res.message)
        }
        this.loading = false
      })
    },
    getAssistDetailData(entryId) {
      this.assistLoading = true
      this.assistData = []
      getAction(this.url.assistList, { entryId })
        .then(res => {
          if (res.success) {
            this.assistData = res.result
          } else {
            this.$message.warning(res.message)
          }
          this.assistLoading = false
        })
        .catch(err => {
          this.$message.warning('请求错误')
          this.assistLoading = false
        })
    }
  }
}
</script>

<style lang="less" scoped>
@import '~@assets/less/tableTheme.less';
.assist-table {
  border-color: #e8e8e8;
  width: 100%;
  .assist-table-title {
    text-align: center !important;
    color: #909399;
    font-size: 14px;
    font-weight: 700;
    padding: 0px 20px !important;
    // line-height: 35px;
    height: 35px;
    background-color: #fafafa;
  }
  .assist-table-item {
    padding: 8px;
    box-sizing: border-box;
    line-height: 20px;
  }
}
</style>
